package cn.yudao.basic.service.impl;


import cn.yudao.basic.mapper.BaseMapper;
import cn.yudao.basic.query.BaseQuery;
import cn.yudao.basic.service.IBaseService;
import cn.yudao.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> loadAll() {
        return baseMapper.LoadAll();
    }

    /**
     * @Title: findByIdT
     * @Description: TODO 根据id
     * @Author: Mr.Jia
     * @Version: 1.0
     * @Date:  2022/6/21 18:56
     * @Parameters:
     * @Return
     */
    @Override
    @Transactional
    public T LoadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * @Title: addT
     * @Description: TODO 往部门表中添加数据
     * @Author: Mr.Jia
     * @Version: 1.0
     * @Date:  2022/6/21 18:57
     * @Parameters:
     * @Return
     */
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    /**
     * @Title: uptT 根据id修改部门表中的数据
     * @Description: TODO
     * @Author: Mr.Jia
     * @Version: 1.0
     * @Date:  2022/6/21 18:58  
     * @Parameters: T部门的实体类
     * @Return
     */
    @Override
    @Transactional
    public void upadte(T t) {
        baseMapper.upadte(t);
    }

    /**
     * @Title: removeT
     * @Description: TODO 根据id删除部门表中的某条数据
     * @Author: Mr.Jia
     * @Version: 1.0
     * @Date:  2022/6/21 18:59
     * @Parameters: id
     * @Return
     */
    @Override
    @Transactional
    public void removeById(Long id) {
        baseMapper.removeById(id);
    }

    @Override
    public void patchRom(Long[] ids) {
        baseMapper.patchRom(ids);
    }


    /**
     * @Title: queryT 返回高级查询以及分页查询的数
     * @Description: TODO
     * @Author: Mr.Jia
     * @Version: 1.0
     * @Date:  2022/6/21 18:59
     * @Parameters:   T部门的实体类
     * @Return PageList 封装当前页数据和总条数的类
     */
    @Override
    public PageList<T> query(BaseQuery baseQuery) {
        // 查询当前页数据
        List<T> rows = baseMapper.query(baseQuery);
        // 查询当前页条数
        Integer total = baseMapper.pagecount(baseQuery);

        return new PageList<T>(total, rows);
    }


}